import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report



col_names = ["id", "diagnosis"] + [f"{stat}_{feature}"
    for stat in ("mean","se","worst")
    for feature in ("radius","texture","perimeter","area","smoothness",
                    "compactness","concavity","concave_points","symmetry","fractal_dimension")]

df = pd.read_csv('data/wdbc.data', header=None, names=col_names)

df['target'] = df['diagnosis'].map({'M': 1, 'B': 0})
# 特征和标签
X = df.drop(['id', 'diagnosis', 'target'], axis=1)
y = df['target']

# 拆分数据集并标准化
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=22)
scaler = StandardScaler()
X_train_sc = scaler.fit_transform(X_train)
X_test_sc = scaler.transform(X_test)

# 训练逻辑回归模型
model = LogisticRegression()
model.fit(X_train_sc, y_train)
print(model.score(X_test_sc, y_test))
# 评估模型
# y_pred = model.predict(X_test_sc)
#
# print(classification_report(y_test, y_pred, target_names=['Benign','Malignant']))